package chat

import (
	"sanguo/node/node_chat"
	ss_rpc "sanguo/protocol/ss/rpc"
	"sanguo/rpc/changeMapChat"

	"github.com/golang/protobuf/proto"
)

type ChangeMapChat struct {
}

func (this *ChangeMapChat) OnCall(replyer *changeMapChat.ChangeMapChatReplyer, arg *ss_rpc.ChangeMapChatReq) {

	node_chat.Debugln("OnCall ChangeMapChat", arg)

	chatMgr.PostTask(func() {

		role := chatMgr.Roles[arg.GetRoleID()]
		resp := &ss_rpc.ChangeMapChatResp{}

		if role == nil {
			resp.Ok = proto.Int32(0)
			replyer.Reply(resp)
			node_chat.Infoln("ChangeMapChat Fail", arg.GetRoleID())
			return
		}

		if !role.ChangeMapChat(arg.GetMapID()) {
			resp.Ok = proto.Int32(0)
			replyer.Reply(resp)
			node_chat.Infoln("ChangeMapChat Fail", arg.GetRoleID())
			return
		}
		resp.Ok = proto.Int32(1)
		node_chat.Infoln("ChangeMapChat OK", arg.GetRoleID())
		replyer.Reply(resp)
	})
}

func init() {
	changeMapChat.Register(&ChangeMapChat{})
}
